<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
	<%@include file="/view/resource.jsp" %>
	<link rel="stylesheet" type="text/css" href="${ctx}/css/base.css">
	<style type="text/css">
		.btnmr {
			margin-right: 5px;
		}

		.panel-tool a.layout-button-up {
			display: none;
		}

		.buttonSend {
			background-color: #009688;
			color: #fff;
			cursor: pointer;
			height: 35px;
			border: none;
			min-width: 80px;
		}

		.buttonSend:hover {
			color: #000;
		}
	</style>
</head>
<body class="topjui-layout">
<!-- Search panel start -->
<div class="ui-search-panel" style="height: 132px;" title="操作框"
     data-options="region:'north',iconCls:'fa fa-search',border:false,split:false">
	<form id="searchForm">
		<input type="hidden" name="dvcId" id="dvcId" value='${dvcId}'/>
		<p class="ui-fields" style="min-width: 620px;">
			<label class="ui-label">围栏名称:</label><input id="name" name="name" data-toggle="topjui-textbox"
			                                            style="width:180px;">
			<label class="ui-label"> 围栏类型:</label>
			<select id="enclosureType" name="enclosureType" style="height: 35px;padding-bottom:5px;">
				<option value="">请选择</option>
				<option value="polygon">多边形区域</option>
				<option value="rect">矩形区域</option>
				<option value="circle">圆形区域</option>
			</select>
			<label class="ui-label"> 绑定状态:</label>
			<select id="bindState" name="bindState" style="height: 35px;padding-bottom:5px;">
				<option value="all">所有</option>
				<option value="none">未绑定</option>
				<option value="success">已绑定</option>
			</select>

			<a href="#" id="btn-search" class="topjui-menubutton btnmr" data-options="iconCls:'fa fa-search',
           btnCls:'topjui-btn'" style="margin-left: 5px;">搜索</a>
		</p>
	</form>
	<form id="entityForm" action="${ctx}/sendEnclosure/send">
		<input type="hidden" name="dvcId" id="dvcIdSend" value="${dvcId}"/>
		<input type="hidden" name="areaIds" id="areaIds" value=""/>
		<input type="hidden" name="bindType" id="bindType" value="terminal"/>
		<p class="ui-fields">
			<select id="configType" name="configType" class="required" style="height: 35px;">
				<%--<option value="0">更新区域</option>--%>
				<option value="0">更新区域</option>
				<option value="1">追加区域</option>
				<option value="3">删除区域</option>
			</select>&nbsp;&nbsp;
			<input type="button" class="buttonSend" value="下发给终端" title="下发给终端" onclick="doBindArea('terminal');"/>&nbsp;&nbsp;

			<%--	<input type="button" class="buttonSend" value="下发给平台" title="下发给平台" onclick="doBindArea('platform');"/>

			<input type="button" class="buttonSend" value="解除绑定" title="解除绑定" onclick="doUnbindArea('');"/>  --%>
			<span style="color:red;"> (注:下发给终端，由终端报警<%--，下发给平台由平台报警--%>)</span>
			<span class="commandMsg"></span>
		</p>
	</form>
</div>
<!--  Search panel end -->

<!-- DataList  -->
<div region="center" border="false">
	<table id="data-list"></table>
</div>
<script type="text/javascript" src="${ctx}/js/common/package.js"></script>
<script type="text/javascript" src="${ctx}/js/common/base.js?v=11"></script>
<script type="text/javascript" src="${ctx}/js/common/DataGrid.js"></script>
<script type="text/javascript" src="${ctx}/js/enclosureBind/enclosureBind.js"></script>
<%--<style type="text/css">
	.datagrid-header-rownumber, .datagrid-cell-rownumber {
		width: 40px;
	}
</style>--%>
<script type="text/javascript">

	function doBindArea(bindType) {
		//获取checkbox选中的行的区域Id
		var checkedItems = $('#data-list').datagrid('getChecked');
		var names = [];
		$.each(checkedItems, function (index, item) {
			names.push(item.enclosureId);
		});
		if (names.length == 0) {
			$.iMessager.alert("提示", "请选择要下发的区域!", 'messager-warning');
			return;
		}
		var configType = $("#configType").val();
		if (configType == '') {
			$.iMessager.alert("提示", "请选择配置类型!", 'messager-warning');
			return;
		}
		var areaIds = names.join(",");
		var dvcIdSend = $("#dvcIdSend").val();
		var params = {areaIds: areaIds, bindType: bindType, configType: configType, dvcId: dvcIdSend};
		var url = path + "/sendEnclosure/send";
		$.getJSON(url, params, function (result) {
			//var result = eval("(" + data + ")");
			//$("#btnQuery").click();
			if (result.success) {
				$.iMessager.alert("提示", "命令已经下发,请稍后刷新状态!", 'messager-info');
			}
			else
				$.iMessager.alert("提示", "提交失败! 错误原因：" + (result.message ? result.message : result.Data), 'messager-error');

		});

	}

	function doUnbindArea(bindType) {
		//获取checkbox选中的行的区域Id
		var checkedItems = $('#data-list').datagrid('getChecked');
		var names = [];
		$.each(checkedItems, function (index, item) {
			names.push(item.enclosureId);
		});
		if (names.length == 0) {
			$.messager.alert("提示", "请选择要下发的区域!", 'messager-warning');
			return;
		}
		var areaIds = names.join(",");
		$("#areaIds").val(areaIds);
		$("#bindType").val(bindType);
		$("#configType").val("3");


		var areaIds = names.join(",");
		var dvcIdSend = $("#dvcIdSend").val();
		var params = {areaIds: areaIds, bindType: bindType, configType: 3, dvcId: dvcIdSend};
		var url = path + "/sendEnclosure/send";
		$.getJSON(url, params, function (result) {
			//$("#btnQuery").click();
			if (result) {
				$.iMessager.alert("提示", "命令已经下发,请稍后刷新状态!", 'messager-info');
			}
			else
				$.iMessager.alert("提示", "提交失败! 错误原因：" + (result.msg ? result.msg : result.Data), 'messager-error');

		});

	}

	$(function () {
		//$("#startTimeSearch").iDatetimebox('setValue', new Date().Format("yyyy-MM-dd") + " 00:00:00");
		//$("#endTimeSearch").iDatetimebox('setValue', new Date().Format("yyyy-MM-dd hh:mm:ss"));
	});
</script>
</body>
</html>
